<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2019/11/12
 * Time: 16:57
 */

namespace app\adminapiv3\controller;

//ips自定义规则

use app\adminapiv3\service\IpsType;

class IpsRule extends BaseController
{
    /**
     * @name 列表
     * @param $host_id
     * @author wx
     * @date 2019/11/12 17:09
     */
    public function list($host_id)
    {
        $params['name'] = $this->filterInput('name','get');
        $params['description'] = $this->filterInput('description','get');
        $params['type'] = $this->filterInput('type','get');
        $params['content'] = $this->filterInput('content','get');
        $params['handle'] = $this->filterInput('handle','get');
        $params['status'] = $this->filterInput('status','get');

        $server = new \app\adminapiv3\service\IpsRule();
        $list = $server->toDo('list', [$host_id, $params]);

        $this->jsonOutPut($list);
    }

    /**
     * @name 首页数据
     * @author wx
     * @date 2019/11/13 10:45
     */
    public function indexData()
    {
        $typeServer = new IpsType();
        $list = $typeServer->freeRule();

        $this->jsonOutPut($list);
    }

    /**
     * @name 启用
     * @author wx
     * @date 2019/11/13 10:44
     */
    public function open($host_id)
    {
        //接收参数
        $id = $this->filterInput('id*','post');
        $params['status'] = $this->filterInput('status*', 'post');

        $server = new \app\adminapiv3\service\IpsRule();
        $server->toDo('modify', [$host_id, $id, $params]);

        $this->jsonOutPut([],true);
        $this->Async('Hgshield', 'rules');
    }

    /**
     * @name 停用
     * @author wx
     * @date 2019/11/13 10:44
     */
    public function close($host_id)
    {
        //接收参数
        $id = $this->filterInput('id*','post');
        $params['status'] = $this->filterInput('status*', 'post');

        $server = new \app\adminapiv3\service\IpsRule();
        $server->toDo('modify', [$host_id, $id, $params]);

        $this->jsonOutPut([],true);
        $this->Async('Hgshield', 'rules');
    }

    /**
     * @name 添加自定义规则
     * @author wx
     * @date 2019/11/13 16:37
     */
    public function add($host_id)
    {
        $params['host_id'] = $host_id;
        $params['name'] = $this->filterInput('name*','post');
        $params['description'] = $this->filterInput('description*','post');
        $params['type'] = $this->filterInput('type*','post');
        $params['content'] = $this->filterInput('content*','post');
        $params['handle'] = $this->filterInput('handle*','post');
        $params['status'] = $this->filterInput('status*','post');
        $params['intranet'] = $this->filterInput('intranet*','post');

        $server = new \app\adminapiv3\service\IpsRule();
        $server->toDo('add', [$params]);

        $this->jsonOutPut([],true);
        $this->Async('Hgshield', 'rules');
    }

    /**
     * @name 删除自定义规则
     * @param $host_id
     * @author wx
     * @date 2020/1/6 11:36
     */
    public function del($host_id)
    {
        //接收参数
        $id = $this->filterInput('id*','post');

        $server = new \app\adminapiv3\service\IpsRule();
        $server->toDo('del', [$host_id, $id]);

        $this->jsonOutPut([],true);
        $this->Async('Hgshield', 'rules');
    }

    /**
     * @name 清空自定义规则
     * @param $host_id
     * @author wx
     * @date 2020/1/6 11:36
     */
    public function clear($host_id)
    {
        $clear = $this->filterInput('clear*','post');

        $server = new \app\adminapiv3\service\IpsRule();
        $server->toDo('clear', [$host_id, $clear]);

        $this->jsonOutPut([],true);
        $this->Async('Hgshield', 'rules');
    }
}